package core.behaviors;

import core.Actor;
import core.Named;
import core.Trashable;
import core.conditions.Condition;
import util.NameSet;

/**
 * Behaviors are steppable, trashable, objects which perform actions on models
 * 
 * A behavior will typically perform some state changing action on a model on
 * each step.  Behaviors can be removed by being marked as trashed.  Also, 
 * behaviors have a collection of conditions which they can check on each
 * step.  When a condition expires then the behavior will trash itself.
 * 
 * @version 1.0
 * @author Alexander Schearer <aas11@duke.edu>
 */
public class Behavior implements Named<Behavior>, Trashable {

	private String myName;

	private NameSet<Condition> myConditions;

	private boolean trashed;

	public Behavior(String name) {
		myName = name;
		myConditions = new NameSet<Condition>();
		trashed = false;
	}

	public Behavior(String name, Condition... c) {
		this(name);
		myConditions.addAll(c);
	}

	public void step() {
		for (Condition condition : myConditions) {
			condition.step();
			if (condition.finished())
				this.trash(true);
		}
	}

	public void step(Actor... actors) {
		step();
	}

	public void trash(boolean jein) {
		trashed = jein;
	}

	public boolean isTrashed() {
		return trashed;
	}

	public String getName() {
		return myName;
	}

	public boolean equals(Behavior i) {
		return myName.equals(i.getName());
	}

	public int compareTo(Behavior o) {
		return myName.compareTo(o.getName());
	}

}
